package com.kugou.miniapp.exception;

import com.kugou.miniapp.utils.ResponseData;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@RestControllerAdvice
class MyExceptionHandler  {
    @ExceptionHandler(value = Exception.class)//指定拦截的异常
    public Object errorHandler(HttpServletRequest request, HttpServletResponse response, Exception e) throws Exception{
        e.printStackTrace();
        ResponseData responseData = new ResponseData<String>();
        responseData.setCode(0);
        responseData.setMsg(e.getMessage().toString());
        return responseData;
    }
}
